import React, { Component } from 'react';
import { Modal } from 'antd-mobile';
import sEmitter from 'storage-emitter';
import jsUtils from '../../../lib/jsUtils';

function sendEvent(eventName, eventData) {
  console.log(`send ${eventName}`);

  sEmitter.emit(eventName, eventData);
}

function registerListener(pageInstance) {

}

function loadPageData(pageInstance) {
  return new Promise((resolve, reject) => {
    resolve();
  });
}

export default class actionNovel extends Component {
  constructor(props) {
    super(props);
    this.state = {
      showPage: false,
    };
  }

  componentDidMount() {
    const classId = jsUtils.getUrlParameter(window.location.search, 'classId');

    jsUtils.setStatePromise(this, {
      classId,
    }).then(() => loadPageData(this)).then(() => {
      registerListener(this);
      sendEvent('createRecordPageIsReady');
    }).catch(() => {
      Modal.alert('提示', '发生错误，请重试', [ {
        text: '知道了',
        onPress: () => {
          jsUtils.nativeGoBack();
        },
      } ]);
    });
  }

  render() {
    const { showPage } = this.state;

    return showPage ? (
      <div className="page">
        <div/>
      </div>
    ) : null;
  }
}
